<?php

include("classes/include.php");

session_start();


if(isset($_POST['ajoutStage']))
{
	
	header("Location: administrationAjoutStage.php");
	
}

if(isset($_POST['modifStage']) && isset($_POST['select']))
{
	
	header("Location: administrationAjoutStage.php?nums=".$_POST['select']);
	
}
else {
	if(isset($_POST['modifStage']))
		header("Location: administrationStage.php");
}
if(isset($_POST['suppStage']) && isset($_POST['select']))
{
	
	
	$numStage = $_POST['select'];
	
	$requeteSupp = new RequeteSQL("DELETE FROM stage WHERE sta_num_stage = ".$numStage);
	$requeteSupp->executeEcriture();
	
	header("Location: administrationStage.php");
	
}
else
{
	if(isset($_POST['suppStage']))
		header("Location: administrationStage.php");
}

if(isset($_POST['enregistrerStage']))
{
	if(isset($_POST['dateDebStage']) && isset($_POST['dateFinStage']))
	{
		$numEtu = $_POST['numEtudiant'];
		$numEnt = $_POST['numEntreprise'];
		$numResp = $_POST['numResponsable'];
		
		$sujetStage = "";
		$missionStage = "";
		
		if(isset($_POST['sujetStage']))
		{
			$sujetStage = $_POST['sujetStage'];
			
		}
		else
			$sujetStage = "rien";
		if(isset($_POST['missionStage']))
			$missionStage = $_POST['missionStage'];
			
		$dateDeb = $_POST['dateDebStage'];
		$dateFin = $_POST['dateFinStage'];
		
		$requeteInsert = new RequeteSQL("INSERT INTO stage VALUES('',
											".$numEtu.",
											".$numEnt.",
											".$numResp.",
											'".$sujetStage."',
											'".$missionStage."',
											'',
											'',
											str_to_date('".$dateDeb."','%d/%m/%Y'),
											str_to_date('".$dateFin."','%d/%m/%Y'))");
		
		$requeteInsert->executeEcriture();
		
		
	}
	
	header("Location: administrationStage.php");
}


if(isset($_POST['creerEntreprise']))
{
	
	header("Location: administrationAjoutEntreprise.php");
	
}

if(isset($_POST['creerResponsable']))
{
	
	header("Location: administrationAjoutResponsable.php");
	
}

if(isset($_POST['modifierStage']))
{
	
	if(isset($_POST['dateDebStage']) && isset($_POST['dateFinStage']))
	{
		
		$numStage = $_POST["numStage"];
	
		$numEtu = $_POST['numEtudiant'];
		$numEnt = $_POST['numEntreprise'];
		$numResp = $_POST['numResponsable'];
		
		$sujetStage = "";
		$missionStage = "";
		
		if(isset($_POST['sujetStage']))
		{
			$sujetStage = $_POST['sujetStage'];
			
		}
		else
			$sujetStage = "rien";
		if(isset($_POST['missionStage']))
			$missionStage = $_POST['missionStage'];
			
		$dateDeb = $_POST['dateDebStage'];
		$dateFin = $_POST['dateFinStage'];
		
		$requeteInsert = new RequeteSQL("UPDATE stage SET 
											sta_num_etudiant = ".$numEtu.",
											sta_num_entreprise = ".$numEnt.",
											sta_num_responsable = ".$numResp.",
											sta_sujet_stage = '".$sujetStage."',
											sta_mission_realise = '".$missionStage."',
											sta_date_debut_stage = str_to_date('".$dateDeb."','%d/%m/%Y'),
											sta_date_fin_stage = str_to_date('".$dateFin."','%d/%m/%Y')
											WHERE sta_num_stage = ".$numStage);
		
		$requeteInsert->executeEcriture();
	}
	
	header("Location: administrationStage.php");
}
else
{
	if(isset($_POST['modifierStage']))
		header("Location: administrationStage.php");
}

?>